package wb.is.besti.edu.cd.javalibgame;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by asus on 2017/12/21.
 */

public class DBHelper extends SQLiteOpenHelper {
    private static final  String DB_NAME = "Score.db";
    private static final String TBL_NAME = "RankTal";
    private SQLiteDatabase db;
    DBHelper(Context context){
        super(context,DB_NAME,null,1);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        this.db = db;
        String CREATE_TBL = "create the MusicTbl(_id integer primary key autoincrement,score text)";
        db.execSQL(CREATE_TBL);
    }
    public void insert(ContentValues values){
        SQLiteDatabase db = getWritableDatabase();
        db.insert(TBL_NAME,null ,values);
        db.close();
    }
    public void del(int id){
        if (db == null){
            db = getWritableDatabase();
        }
        db.delete(TBL_NAME,"_id=?",new String[]{String.valueOf(id)});
    }
    public void close(){
        if (db!=null)
            db.close();
    }
    public Cursor query(){
        SQLiteDatabase db = getReadableDatabase();
        Cursor cursor = db.query(TBL_NAME,null,null,null,null,null,null);
        return cursor;
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
